package 剑指offer;

import 剑指offer.ListNode;

public class 从头到尾打印链表 {
    public int[] reversePrint(ListNode head) {
        //找到链表的长度
        ListNode cur=head;
        int num=0;
        while (cur!=null){
               num++;
               cur=cur.next;
        }
        int[] ints = new int[num];
        for (int i = num-1; i >=0 ; i--) {
            ints[i]=head.val;
            head=head.next;
        }
        return  ints;
    }
}
